Skip to content

Fix/bug fixes and updates #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jun 6, 2025
Merged

Fix/bug fixes and updates #80

merged 11 commits into from
Jun 6, 2025

Conversation

tractorss
Copy link
Contributor

@tractorss tractorss commented Jun 6, 2025

  • documentation update

  • ids to select wrappers in accordion

  • add aria label override in Modal

  • Field Errors for Form Fields

  • Option to hide the field errors

  • BigNumberField

    • Field errors
    • make formatConfig local, instead of setting on global BigNumber config
    • avoid scrolling page when using wheel to increment or decrement
  • Draggable List

    • use custom useList hook, since useListData from react-aria is immutable and does not track items changes
    • update rendering of lists to not use DynamicCollection, since that caches the remove call and causes inconsistent behaviour.
    • show trash icon on selection, for mobile devices

PR-Codex overview

This PR introduces enhancements to several components in the library, adding validation features and error handling for form fields. It also updates the Modal component and various story files for better demonstration of these features.

Detailed summary

  • Added ariaLabel prop to the Modal component.
  • Introduced showFieldError and fieldErrorProps to TextField, TextArea, NumberField, Searchbar, and BigNumberField for error handling.
  • Updated stories for TextField, TextArea, NumberField, Searchbar, and BigNumberField to demonstrate validation.
  • Enhanced DraggableList to manage items with improved state handling.
  • Updated package.json version from 3.3.4 to 3.4.5 and added new dependencies.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Summary by CodeRabbit

  • New Features

    • Added support for displaying validation errors in NumberField, TextField, TextArea, Searchbar, and BigNumberField components, with customizable error messages and styling.
    • Introduced custom validation logic for form fields, allowing tailored error handling.
    • Enhanced Modal accessibility with an optional aria-label property.
    • Improved AccordionItem and DraggableList UI responsiveness and interactivity.
    • Added a custom useList hook for advanced list management.
  • Documentation

    • Clarified and expanded CSS import instructions in the README for both Tailwind and non-Tailwind setups.
  • Chores

    • Added lodash and its type definitions as dependencies.
  • Tests

    • Updated Storybook stories to showcase new validation features and error display options for form components.
    • Enhanced DraggableList story with dynamic item addition and state management.

Copy link

netlify bot commented Jun 6, 2025

Deploy Preview for kleros-v2-ui-storybook ready!

Name Link
🔨 Latest commit f1234cc
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-ui-storybook/deploys/6842efc22bd9370008d58479
😎 Deploy Preview https://deploy-preview-80--kleros-v2-ui-storybook.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Contributor

coderabbitai bot commented Jun 6, 2025

Walkthrough

This update introduces enhanced validation error handling and accessibility for form components, adds a custom list management hook, and refines documentation and stories. The changes include improved error display via new props, a new useList hook for list state, accessibility improvements in modals and form fields, and expanded Storybook examples.

Changes

Files/Groups Change Summary
README.md Expanded and clarified CSS import instructions, especially for Tailwind users; corrected import examples.
package.json Added lodash to dependencies and @types/lodash to devDependencies; updated version to 3.4.5.
src/lib/accordion/accordion-item.tsx Added ARIA IDs, responsive padding, and icon class changes for accessibility/UI consistency.
src/lib/container/modal.tsx Added optional ariaLabel prop for accessibility, defaulting to "Modal".
src/lib/draggable-list/index.tsx, src/lib/draggable-list/useList.ts Replaced react-stately with new useList hook for item management; updated handlers and rendering logic.
src/lib/form/bignumber-field/index.tsx, src/lib/form/bignumber-field/useBigNumberField.tsx Improved validation, error display, and accessibility; removed dynamic IDs; added error message rendering and ARIA attributes.
src/lib/form/number-field.tsx, src/lib/form/searchbar.tsx, src/lib/form/text-area.tsx, src/lib/form/text-field.tsx Added showFieldError and fieldErrorProps props to support custom validation error display using FieldError.
src/stories/bignumber-field.stories.tsx, src/stories/number-field.stories.tsx, src/stories/searchbar.stories.tsx, src/stories/text-area.stories.tsx, src/stories/text-field.stories.tsx Enhanced "Required" stories with custom validation logic, error display, and documentation comments; added interactivity to DraggableList story.
src/stories/draggable-list.stories.tsx Made DraggableList story interactive by adding state management and an "Add Item" button.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant FormComponent
  participant ValidationLogic
  participant FieldErrorDisplay

  User->>FormComponent: Input/change value
  FormComponent->>ValidationLogic: Validate input (on change/blur)
  ValidationLogic-->>FormComponent: Validation result (valid/invalid, message)
  FormComponent->>FieldErrorDisplay: Show error if invalid and showFieldError
  FieldErrorDisplay-->>User: Display error message
Loading
sequenceDiagram
  participant Consumer
  participant useList
  participant ListComponent

  Consumer->>useList: Initialize with items, onChange callback
  ListComponent->>useList: getItem, moveBefore, moveAfter, remove
  useList-->>ListComponent: Updated items
  useList-->>Consumer: onChange(updatedItems) (if provided)
Loading

Suggested reviewers

  • alcercu

Poem

In fields of forms where errors may hide,
Now rabbits hop with validation as their guide.
Lists rearrange with a gentle twitch,
Modals speak their purpose without a glitch.
Stories bloom with error tales anew—
🐇 Code grows clearer, thanks to all of you!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d0820e6 and f1234cc.

📒 Files selected for processing (1)
  • package.json (3 hunks)
✅ Files skipped from review due to trivial changes (1)
  • package.json
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Redirect rules - kleros-v2-ui-storybook
  • GitHub Check: Header rules - kleros-v2-ui-storybook
  • GitHub Check: Pages changed - kleros-v2-ui-storybook

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 13

🧹 Nitpick comments (6)
README.md (2)

58-63: Refine grammar for import instruction.
Change

For Non-tailwind apps, import the CSS at top level of your app.

to

For non-Tailwind apps, import the CSS at the top level of your application.
🧰 Tools
🪛 LanguageTool

[uncategorized] ~60-~60: You might be missing the article “the” here.
Context: ...or Non-tailwind apps, import the CSS at top level of your app. ```javascript ...

(AI_EN_LECTOR_MISSING_DETERMINER_THE)


66-70: Clarify and simplify Tailwind app import paths.
Relying on a relative ../../../node_modules path may break in many setups. Consider using a module alias or tilde import, for example:

@import "~@kleros/ui-components-library/dist/assets/theme.css";

Also verify that your CSS toolchain supports the @source directive or document its purpose.

src/stories/bignumber-field.stories.tsx (1)

189-217: Well-implemented Required story following established patterns.

The story correctly demonstrates validation with BigNumber-specific logic using .eq(0) and follows the same pattern as other form field stories. The form structure and error handling are consistent.

Minor suggestion: Consider making the placeholder more descriptive:

-        placeholder="Enter '0'"
+        placeholder="Enter '0' to see validation error"
package.json (1)

55-55: Consider whether lodash is necessary for just deep equality checks.

The only usage of lodash in the codebase appears to be for deep equality comparison in useList.ts. Consider using a more lightweight alternative like fast-deep-equal or implementing a custom deep comparison function if this is the only use case. This would reduce the bundle size.

Also applies to: 97-97

src/stories/draggable-list.stories.tsx (1)

37-37: Consider using consistent render function naming.

The render function is named Render with a capital R, while convention typically uses lowercase for function names.

Apply this diff for consistency:

-  render: function Render(args) {
+  render: function render(args) {
src/lib/draggable-list/index.tsx (1)

1-1: Remove unnecessary React namespace import.

Modern React (17+) with the new JSX transform doesn't require importing React when only using JSX.

Apply this diff:

-import React from "react";
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 957f17c and 0a33457.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (18)
  • README.md (2 hunks)
  • package.json (2 hunks)
  • src/lib/accordion/accordion-item.tsx (2 hunks)
  • src/lib/container/modal.tsx (2 hunks)
  • src/lib/draggable-list/index.tsx (5 hunks)
  • src/lib/draggable-list/useList.ts (1 hunks)
  • src/lib/form/bignumber-field/index.tsx (5 hunks)
  • src/lib/form/bignumber-field/useBigNumberField.tsx (14 hunks)
  • src/lib/form/number-field.tsx (4 hunks)
  • src/lib/form/searchbar.tsx (3 hunks)
  • src/lib/form/text-area.tsx (4 hunks)
  • src/lib/form/text-field.tsx (4 hunks)
  • src/stories/bignumber-field.stories.tsx (2 hunks)
  • src/stories/draggable-list.stories.tsx (2 hunks)
  • src/stories/number-field.stories.tsx (2 hunks)
  • src/stories/searchbar.stories.tsx (2 hunks)
  • src/stories/text-area.stories.tsx (2 hunks)
  • src/stories/text-field.stories.tsx (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (8)
src/lib/container/modal.tsx (1)
src/stories/modal.stories.tsx (1)
  • Modal (26-48)
src/stories/bignumber-field.stories.tsx (3)
src/stories/number-field.stories.tsx (2)
  • Required (81-121)
  • Default (42-49)
src/stories/text-field.stories.tsx (2)
  • Required (81-121)
  • Default (42-49)
src/stories/form.stories.tsx (1)
  • Form (19-44)
src/lib/accordion/accordion-item.tsx (1)
src/utils/index.ts (1)
  • cn (4-6)
src/lib/form/searchbar.tsx (1)
src/utils/index.ts (1)
  • cn (4-6)
src/lib/form/bignumber-field/index.tsx (2)
src/lib/form/bignumber-field/useBigNumberField.tsx (1)
  • useBigNumberField (91-691)
src/utils/index.ts (1)
  • cn (4-6)
src/lib/form/text-field.tsx (1)
src/utils/index.ts (1)
  • cn (4-6)
src/lib/form/number-field.tsx (1)
src/utils/index.ts (1)
  • cn (4-6)
src/lib/form/text-area.tsx (1)
src/utils/index.ts (1)
  • cn (4-6)
🪛 LanguageTool
README.md

[uncategorized] ~60-~60: You might be missing the article “the” here.
Context: ...or Non-tailwind apps, import the CSS at top level of your app. ```javascript ...

(AI_EN_LECTOR_MISSING_DETERMINER_THE)

🪛 Biome (1.9.4)
src/lib/form/bignumber-field/useBigNumberField.tsx

[error] 635-635: Invalid typeof comparison value: this expression is not a string literal

not a string literal

(lint/suspicious/useValidTypeof)

🔇 Additional comments (35)
src/lib/accordion/accordion-item.tsx (2)

32-32: Responsive horizontal padding on the button.
The addition of px-4 md:px-8 correctly enhances the button’s padding across breakpoints without side effects.


39-41: Prevent icon shrinking.
Adding shrink-0 to the Minus and Plus icons ensures they maintain their intended size within the flex layout.

Also applies to: 43-45

README.md (1)

94-95: Approve separated import statements.
Splitting into

@import tailwindcss;
@import "../../../node_modules/@kleros/ui-components-library/dist/assets/theme.css";

ensures proper load order.

src/lib/container/modal.tsx (2)

17-17: Good accessibility enhancement with proper typing.

The optional ariaLabel prop is well-typed and follows accessibility best practices.


41-41: Proper aria-label implementation with sensible fallback.

The implementation correctly applies the aria-label to the Dialog component with a reasonable default value when no custom label is provided.

src/stories/bignumber-field.stories.tsx (1)

1-1: Good addition of required imports for the new story.

The React and Form/Button imports are necessary for the new Required story functionality.

Also applies to: 7-7

src/stories/number-field.stories.tsx (2)

80-80: Clear documentation for the Required story.

The JSDoc comment effectively explains the story's purpose and available customization options.


92-110: Excellent validation implementation with custom error rendering.

The enhanced Required story properly demonstrates:

  • Field error visibility with showFieldError
  • Appropriate validation logic for number type (value === 0)
  • Custom error styling and rendering through fieldErrorProps
  • Consistent styling with other form field stories

The implementation follows the established pattern perfectly.

src/stories/text-field.stories.tsx (2)

80-80: Consistent documentation across form field stories.

The JSDoc comment matches the pattern established in other form field stories, providing clear guidance on the story's purpose.


92-110: Perfect consistency with other form field validation stories.

The implementation follows the exact same pattern as the NumberField story with appropriate adaptations for text input:

  • String-based validation (value === "admin")
  • Identical error rendering structure
  • Consistent styling and component structure

This consistency across form field stories is excellent for maintainability and user experience.

src/lib/form/searchbar.tsx (2)

4-6: LGTM! Well-structured interface extension for validation support.

The addition of FieldError imports and the new props follow the established pattern. The JSDoc comments provide clear guidance on usage and link to relevant documentation.

Also applies to: 23-30


38-39: LGTM! Proper implementation of conditional error display.

The conditional rendering logic is correct and the className merging using the cn utility properly handles both default styling and custom overrides. The error styling classes are consistent with the design system.

Also applies to: 72-82

src/lib/form/bignumber-field/index.tsx (1)

83-83: LGTM! Good addition of invalid state styling.

The invalid:border-klerosUIComponentsError class provides proper visual feedback for invalid states.

src/stories/text-area.stories.tsx (2)

80-80: LGTM! Clear documentation for the story's purpose.

The JSDoc comment effectively explains the story's functionality and optional customization capabilities.


92-110: LGTM! Excellent demonstration of validation features.

The story effectively showcases the new validation capabilities with:

  • showFieldError enabling error display
  • Custom validate function with practical example
  • fieldErrorProps demonstrating custom error rendering
  • Proper styling and list structure for multiple errors

This serves as both documentation and functional testing for the new features.

src/lib/form/text-area.tsx (2)

15-16: LGTM! Consistent interface extension for validation support.

The addition of FieldError imports and props follows the established pattern across form components. The JSDoc comments clearly explain the purpose and provide documentation links.

Also applies to: 33-40


52-53: LGTM! Proper implementation of conditional error display.

The conditional rendering and className merging are implemented correctly, maintaining consistency with other form components. The error styling follows the design system conventions.

Also applies to: 116-126

src/lib/form/text-field.tsx (4)

15-16: LGTM: Proper imports for field error functionality.

The imports for FieldError and FieldErrorProps are correctly added from react-aria-components to support the new validation error display feature.


30-37: LGTM: Well-documented props with clear purpose.

The new props are properly typed and documented:

  • showFieldError provides a boolean toggle for error display
  • fieldErrorProps allows customization of the FieldError component
  • Good documentation explains this is an alternative to the existing message prop

47-48: LGTM: Props correctly destructured.

The new props are properly added to the component parameters and destructured appropriately.


125-135: LGTM: Clean conditional rendering with proper class merging.

The implementation correctly:

  • Uses conditional rendering based on showFieldError
  • Spreads fieldErrorProps to allow full customization
  • Merges CSS classes using the cn utility to handle Tailwind conflicts
  • Renders fieldErrorProps.children for content control
src/lib/form/number-field.tsx (4)

18-19: LGTM: Consistent imports across form components.

The imports match the pattern established in TextField, maintaining consistency across the form component library.


34-41: LGTM: Consistent prop definitions.

The prop definitions are identical to TextField, ensuring a uniform API across form components. The documentation is clear and helpful.


54-55: LGTM: Proper parameter handling.

The new props are correctly destructured in the component parameters.


186-196: LGTM: Consistent FieldError implementation.

The FieldError rendering is implemented identically to TextField, maintaining consistency across the component library. The class merging and prop spreading are handled correctly.

src/stories/searchbar.stories.tsx (2)

46-46: LGTM: Updated comment reflects new functionality.

The comment accurately describes the story now demonstrates both required validation and custom error styling.


58-77: LGTM: Comprehensive validation demo.

The story effectively demonstrates the new validation features:

  • showFieldError enables error display
  • validate function provides custom validation logic
  • fieldErrorProps shows how to customize error rendering with styled list items
  • The demo validation logic is simple but effective for showcasing functionality
src/lib/form/bignumber-field/useBigNumberField.tsx (8)

9-10: LGTM: Appropriate hook imports.

The useCallback and useId imports are correctly added to support the new memoization and ID generation functionality.


68-76: LGTM: Well-documented validation props.

The new props are properly typed and documented:

  • validate function provides custom validation
  • showFieldError enables error display
  • fieldErrorClassName allows error styling customization

93-97: LGTM: BigNumber configuration enhancement.

Moving the BigNumber configuration to a useEffect ensures it runs after component mount and the empty dependency array ensures it only runs once.


113-115: LGTM: Proper ID generation.

Using useId for generating unique IDs when none is provided follows React best practices for accessibility.


117-121: LGTM: Memoized formatting function.

The formatBigNumber callback is properly memoized with formatOptions as a dependency, preventing unnecessary re-renders while ensuring the function updates when format options change.


144-147: LGTM: Validation state management.

The validation result state is properly structured with isInvalid flag and optional error message.


524-539: LGTM: Effective scroll prevention.

The wheel event handling properly prevents page scrolling when the input is focused. The event listener cleanup in the useEffect return function prevents memory leaks.


607-607: LGTM: Proper accessibility integration.

The aria-invalid attribute is correctly set based on the validation result, improving accessibility for screen readers.

coderabbitai[bot]
coderabbitai bot previously approved these changes Jun 6, 2025
coderabbitai[bot]
coderabbitai bot previously approved these changes Jun 6, 2025
alcercu
alcercu previously approved these changes Jun 6, 2025
Copy link
Contributor

@alcercu alcercu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@tractorss tractorss dismissed stale reviews from alcercu and coderabbitai[bot] via f1234cc June 6, 2025 13:40
Copy link

sonarqubecloud bot commented Jun 6, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
12.7% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@tractorss tractorss merged commit 6533622 into main Jun 6, 2025
8 of 9 checks passed
@tractorss tractorss deleted the fix/bug-fixes-and-updates branch June 6, 2025 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants